.var SCR_BORDER_COLOR = $d020
.var SCR_BACK_COLOR = $d021	

.var JOY0 = $dc00

.var SPR0_X = $d000
.var SPR0_ADDR = $07f8
.var SPR0_COLOR = $d027

.var SPR_ENABLE = $d015
.var SPR_MULTICOLOR_MODE = $d01C
.var SPR_STRECH_X = $D01D
.var SPR_STRECH_Y = $D017
.var SPR_X_CARRY = $d010
.var SPR_MULTICOLOR_1 = $d025
.var SPR_MULTICOLOR_2 = $d026

.var SCRL_HORIZ = $d016

.var COLOR_RAM = $d800

.var THIS = $10

.var DYN_ORIENTATION = $00
.var DYN_PUSHING = $01
.var DYN_AREIAL = $02
.var DYN_MIN_XVELO = $03
.var DYN_MAX_XVELO = $05
.var DYN_RUN_ACCEL = $07
.var DYN_BREAK_ACCEL = $09
.var DYN_JUMP_VELO = $0b
.var DYN_XPOS = $0d
.var DYN_YPOS = $10
.var DYN_XVELO = $13
.var DYN_YVELO = $15
.var DYN_LSTAND = $17
.var DYN_RSTAND = $19
.var DYN_LJUMP = $1b
.var DYN_RJUMP = $1d
.var DYN_LRUN = $1f
.var DYN_RRUN = $21

//copy macros
.macro copy(from,to,size)
{
	.for (var i=0;i<size;i++)
	{
		lda from+i
		sta to+i
	}
}

.macro writeAddress(location,label)
{
	lda #<label
	sta location
	lda #>label
	sta location+1
}

.macro setThis(label)
{
	:writeAddress(THIS,label)
}

.macro copyFromThis(to,size)
{
	.for (var i=0;i<size;i++)
	{
		lda (THIS),Y
		iny
		sta to+i
	}
}

.macro copyToThis(from,size)
{
	.for (var i=0;i<size;i++)
	{
		lda from+i
		sta (THIS),Y
		iny
	}
}

.macro copyFromAddrOff(addr,offset,to,size)
{
	ldy #offset
	.for (var i=0;i<size;i++)
	{
		lda (addr),Y
		iny
		sta to+i
	}
}


.macro copyToAddrOff(addr,offset,from,size)
{
	ldy #offset
	.for (var i=0;i<size;i++)
	{
		lda from+i
		sta (addr),Y
		iny
	}
}

.macro copyFromThisOff(offset,to,size)
{
	:copyFromAddrOff(THIS,offset,to,size)
}


.macro copyToThisOff(offset,from,size)
{
	:copyToAddrOff(THIS,offset,from,size)
}

//numerical macros
.var NUM1 = $20
.var NUM2 = $24
.var NUM3 = $28
.var NUM4 = $2b

.macro setZero(NUM,size)
{
	lda #$00
	.for (var i=0;i<size;i++)
	{
		sta NUM+i
	}
}

.macro Add(OP1,OP2,RET,size)
{
	clc
	.for (var i=0;i<size;i++)
	{
		lda OP1+i
		adc OP2+i
		sta RET+i 
	}
}

.macro Sub(OP1,OP2,RET,size)
{
	sec
	.for (var i=0;i<size;i++)
	{
		lda OP1+i
		sbc OP2+i
		sta RET+i 
	}
}

.macro branchIfNotZero(NUM,size,branch)
{
	.for (var i=0;i<size;i++)
	{
		lda NUM+i
		cmp #$00
		bne branch
	}
}

.macro branchIfPositiove(NUM,size,branch)
{
	lda NUM+size-1
	and #%10000000
	cmp #$00
	beq branch
}

.macro branchIfNegative(NUM,size,branch)
{
	lda NUM+size-1
	and #%10000000
	cmp #$00
	bne branch
}

.macro branchIfLesser(OP1,OP2,size,branch)
{
	:Sub(OP1,OP2,NUM4,size)
	:branchIfNegative(NUM4,size,branch)
}

.macro branchIfGreater(OP1,OP2,size,branch)
{
	:Sub(OP1,OP2,NUM4,size)
	:branchIfPositiove(NUM4,size,branch)
}

.macro branchIfNotEqual(OP1,OP2,size,branch)
{
	.for (var i=0;i<size;i++)
	{
		lda OP1+i
		cmp OP2+i
		bne branch
	}
}

.macro UpscaleSignedNum(NUM,fromSize,toSize)
{
	:branchIfPositiove(NUM,fromSize,upscale_positive)
	lda #$ff //if negative
	jmp upscale_positive_end
upscale_positive:
	lda #$00
upscale_positive_end:
	.for (var i = fromSize;i<toSize;i++)
	{
		sta NUM+i
	}
}
